//
//  ImageUIButton.m
//  ImageButton
//
//  Created by Handymood on 11-5-20.
//  Copyright 2011 __Hanydmood__. All rights reserved.
//

#import "ImageUIButton.h"

@implementation ImageUIButton

@synthesize button_id;
@synthesize imageNormal;
@synthesize imageDown;

-(void) addButtonWithImageLink:(NSString *) normalStatusImgLink 
             downStatusImgLink:(NSString *) downStatusImgLink
{
    NSString *fileNamePrefix_Normal = [normalStatusImgLink substringWithRange:NSMakeRange(0, [normalStatusImgLink  length] - 4)];
    NSString *fileNameSuffix_Normal = [normalStatusImgLink substringWithRange:NSMakeRange([normalStatusImgLink length]-3,3)];
    
    NSString *fileNamePrefix_Down = [downStatusImgLink substringWithRange:NSMakeRange(0, [downStatusImgLink length] - 4)];
    NSString *fileNameSuffix_Down = [downStatusImgLink substringWithRange:NSMakeRange([downStatusImgLink length]-3,3)];
    
    [self addButtonFace:fileNamePrefix_Normal normalImgSuffix:fileNameSuffix_Normal
            downImgPrefix:fileNamePrefix_Down downImgSuffix:fileNameSuffix_Down];
}

-(void)addButtonFace:(NSString *)normalPrefix 
     normalImgSuffix:(NSString *) normalSuffix 
       downImgPrefix: (NSString*) downPrefix  
       downImgSuffix:(NSString*) downSuffix
{
    self.backgroundColor = [UIColor clearColor];
    NSString *fileLocation = [[NSBundle mainBundle] pathForResource:normalPrefix ofType:normalSuffix];
    NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];
    imageNormal = [[UIImage alloc] initWithData:imageData]; 
    
    NSString *fileLocation2 = [[NSBundle mainBundle] pathForResource:downPrefix ofType:downSuffix];
    NSData *imageData2 = [NSData dataWithContentsOfFile:fileLocation2];
    imageDown = [[UIImage alloc] initWithData:imageData2]; 
    
    [self setBackgroundImage:imageNormal forState:UIControlStateNormal];
    [self setBackgroundImage:imageDown forState:UIControlStateHighlighted];
    
    self.frame = CGRectMake(0, 0, imageNormal.size.width, imageNormal.size.height);
    
    [imageNormal release];
    [imageDown release];
}


-(void)setXY:(CGFloat) inx 
        offy:(CGFloat) iny
{
    self.frame = CGRectMake(inx, iny, self.frame.size.width, self.frame.size.height);
}

@end
